/**
 * 
 */
package com.iss.card.view.store;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageView;

/**
 * @author dtdh
 *
 */
public class RecycleableImageView extends ImageView {
	private final static String TAG = RecycleableImageView.class.getSimpleName();
	private Bitmap mBitmap = null;
	/**
	 * @param context
	 */
	public RecycleableImageView(Context context) {
		super(context);
	}

	/**
	 * @param context
	 * @param attrs
	 */
	public RecycleableImageView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public void recycleBitmap() {
		Log.d(TAG, "recycleBitmap: " + this);
		this.setImageDrawable(null);
		if (mBitmap != null && !mBitmap.isRecycled()) {
			mBitmap.recycle();
			mBitmap = null;
		}
	}

	/* (non-Javadoc)
	 * @see android.widget.ImageView#onDetachedFromWindow()
	 */
	@Override
	protected void onDetachedFromWindow() {
		super.onDetachedFromWindow();
//		Log.d(TAG, "onDetachedFromWindow: ");
		this.recycleBitmap();
	}
}
